#include "gtest/gtest.h"
#include "stack.h"  // 假设你的 Stack 类定义在 stack.h 文件中

// 测试空栈的行为
TEST(StackTest, EmptyStack) {
    Stack<int> stack;
    EXPECT_TRUE(stack.empty()) << "Stack should be empty when initialized.";
}

// 测试 push 方法
TEST(StackTest, Push) {
    Stack<int> stack;
    stack.push(10);
    EXPECT_FALSE(stack.empty()) << "Stack should not be empty after pushing an element.";
    EXPECT_EQ(stack.top(), 10) << "Top of the stack should be the last pushed element.";
}

// 测试 pop 方法
TEST(StackTest, Pop) {
    Stack<int> stack;
    stack.push(10);
    stack.push(20);
    EXPECT_EQ(stack.top(), 20) << "Top of the stack should be 20 before popping.";
    stack.pop();
    EXPECT_EQ(stack.top(), 10) << "Top of the stack should be 10 after popping.";
    stack.pop();
    EXPECT_TRUE(stack.empty()) << "Stack should be empty after popping all elements.";
}

// 测试 top 方法的异常情况
TEST(StackTest, TopOnEmptyStack) {
    Stack<int> stack;
    EXPECT_DEATH(stack.top(), ".*");  // 确保访问空栈的 top 会触发断言失败
}

// 测试 pop 方法的异常情况
TEST(StackTest, PopOnEmptyStack) {
    Stack<int> stack;
    EXPECT_DEATH(stack.pop(), ".*");  // 确保对空栈调用 pop 会触发断言失败
}

// 测试多种类型
TEST(StackTest, MultipleTypes) {
    Stack<std::string> stack;
    stack.push("Hello");
    stack.push("World");
    EXPECT_EQ(stack.top(), "World") << "Top of the stack should be 'World'.";
    stack.pop();
    EXPECT_EQ(stack.top(), "Hello") << "Top of the stack should be 'Hello' after popping.";
    stack.pop();
    EXPECT_TRUE(stack.empty()) << "Stack should be empty after popping all elements.";
}